﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    using DAL.Entities;

    public class KhachHangDAL : BaseDAL, UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT * from khachhang";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @" DELETE FROM khachhang WHERE ma_kh = '{0}' ";
            sql = string.Format(sql,id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Khach_Hang)obj;
            string sql = @"set dateformat mdy; INSERT INTO khachhang(ma_kh,ten_kh,ngaysinh,cmnd,sdt,diachi) VALUES('{0}',N'{1}','{2}','{3}','{4}',N'{5}')";
            sql = string.Format(sql,o.ma_kh,o.ten_kh,o.namsinh_kh,o.cmnd_kh,o.sdt_kh,o.diachi_kh);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Khach_Hang)obj;
            string sql = @"set dateformat mdy; UPDATE khachhang SET ten_kh=N'{0}', ngaysinh='{1}', cmnd='{2}', sdt='{3}', diachi=N'{4}' WHERE ma_kh='{5}' ";
            sql = string.Format(sql, o.ten_kh, o.namsinh_kh, o.cmnd_kh, o.sdt_kh, o.diachi_kh, o.ma_kh);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        

    }
}
